package com.xuetang9.t9.hotel.services.impl;

import com.xuetang9.t9.hotel.beans.RoomType;
import com.xuetang9.t9.hotel.mapper.IRoomInfoMapper;
import com.xuetang9.t9.hotel.mapper.IRoomTypeMapper;
import com.xuetang9.t9.hotel.services.IRoomTypeService;
import com.xuetang9.t9.hotel.utils.PageBean;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service("RoomTypeServiceImpl")
public class RoomTypeServiceImpl implements IRoomTypeService {
    @Autowired
    private IRoomTypeMapper roomTypeMapper;
    @Autowired
    private IRoomInfoMapper roomInfoMapper;

    @Override
    public boolean save(RoomType type) {
        return roomTypeMapper.insert(type) > 0;
    }

    @Override
    public boolean remove(Integer id) {
        roomInfoMapper.delete(roomTypeMapper.selectById(id).getTypeId());
        return roomTypeMapper.delete(id) > 0;
    }

    @Override
    public boolean alter(RoomType type) {
        return roomTypeMapper.update(type) > 0;
    }

    @Override
    public PageBean findByAll() {
        PageBean pageBean = new PageBean();
        pageBean.ok(roomTypeMapper.selectAll());
        return pageBean;
    }

    @Override
    public PageBean findByTypeAll() {
        PageBean pageBean = new PageBean();
        pageBean.ok(roomTypeMapper.selectByTypeAll());
        return pageBean;
    }

    @Override
    public RoomType findById(Integer id) {
        return roomTypeMapper.selectById(id);
    }
}
